home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_08 / phillip2 / cips5.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-24  |  43.0 KB  |  1,585 lines

  1.  
  2.    /*************************** 
  3.    * 
  4.    *   cips5.c 
  5.    *   COMPOSITE FILE COMPRISING: 
  6.    *   boole.c 
  7.    *   overlay.c 
  8.    *   txtrsubs.c 
  9.    * 
  10.    ***************************\ 
  11.  
  12.  
  13.  
  14.  
  15.     /***********************************************
  16.     *
  17.     *       file d:\cips\boole.c
  18.     *
  19.     *       Functions: This file contains
  20.     *          and_image
  21.     *          or_image
  22.     *          xor_image
  23.     *          nand_image
  24.     *          nor_image
  25.     *          not_image
  26.     *
  27.     *       Purpose:
  28.     *          These functions implement the basic
  29.     *          Boolean algebra functions AND, OR,
  30.     *          XOR, NAND, NOR, and NOT.
  31.     *
  32.     *       External Calls:
  33.     *          wtiff.c - create_file_if_needed
  34.     *                    write_array_into_tiff_image
  35.     *          tiff.c - read_tiff_header
  36.     *          rtiff.c - read_tiff_image
  37.     *          numcvrt.c - get_integer
  38.     *
  39.     *       Modifications:
  40.     *          3 March 1993 - created
  41.     *
  42.     ***********************************************/
  43.  
  44.  
  45. #include "cips.h"
  46.  
  47.  
  48.  
  49.    /**************************************************
  50.    *
  51.    *   and_image(...
  52.    *
  53.    *   This function performs the Boolean AND 
  54.    *   operation.  The output image = in1 AND in2.
  55.    *   This works for 0 non-zero images.  If both
  56.    *   in1 and in2 are non-zero, the output = in1.
  57.    *
  58.    ***************************************************/
  59.  
  60. and_image(in1_name, in2_name, out_name,
  61.           the_image, out_image,
  62.           il1, ie1, ll1, le1,
  63.           il2, ie2, ll2, le2,
  64.           il3, ie3, ll3, le3)
  65.    char   in1_name[], in2_name[], out_name[];
  66.    int    il1, ie1, ll1, le1,
  67.           il2, ie2, ll2, le2,
  68.           il3, ie3, ll3, le3;
  69.    short  the_image[ROWS][COLS],
  70.           out_image[ROWS][COLS];
  71. {
  72.    int    i, j, length, width;
  73.    struct tiff_header_struct image_header;
  74.  
  75.    create_file_if_needed(in1_name, out_name, out_image);
  76.  
  77.    read_tiff_image(in1_name, the_image,
  78.                    il1, ie1, ll1, le1);
  79.    read_tiff_image(in2_name, out_image,
  80.                    il2, ie2, ll2, le2);
  81.  
  82.    for(i=0; i<ROWS; i++){
  83.       if ( (i%10) == 0) printf(" %d", i);
  84.       for(j=0; j<COLS; j++){
  85.          if( the_image[i][j] != 0   &&
  86.              out_image[i][j] != 0)
  87.              out_image[i][j] = the_image[i][j];
  88.          else
  89.              out_image[i][j] = 0;
  90.       }  /* ends loop over j */
  91.    }  /* ends loop over i */
  92.  
  93.    write_array_into_tiff_image(out_name, out_image,
  94.                                il3, ie3, ll3, le3);
  95.  
  96. } /* ends and_image */
  97.  
  98.  
  99.  
  100.  
  101.  
  102.    /**************************************************
  103.    *
  104.    *   or_image(...
  105.    *
  106.    *   This function performs the Boolean OR 
  107.    *   operation.  The output image = in1 OR in2.
  108.    *   This works for 0 non-zero images.  If both
  109.    *   in1 and in2 are non-zero, the output = in1.
  110.    *   If in1 is non-zero, the output = in1.
  111.    *   If in1 is zero and in2 is non-zero, the
  112.    *   output = in2.
  113.    *
  114.    ***************************************************/
  115.  
  116. or_image(in1_name, in2_name, out_name,
  117.          the_image, out_image,
  118.          il1, ie1, ll1, le1,
  119.          il2, ie2, ll2, le2,
  120.          il3, ie3, ll3, le3)
  121.    char  in1_name[], in2_name[], out_name[];
  122.    int   il1, ie1, ll1, le1,
  123.          il2, ie2, ll2, le2,
  124.          il3, ie3, ll3, le3;
  125.    short the_image[ROWS][COLS],
  126.          out_image[ROWS][COLS];
  127. {
  128.    int    i, j, length, width;
  129.    struct tiff_header_struct image_header;
  130.  
  131.    create_file_if_needed(in1_name, out_name, out_image);
  132.  
  133.    read_tiff_image(in1_name, the_image,
  134.                    il1, ie1, ll1, le1);
  135.    read_tiff_image(in2_name, out_image,
  136.                    il2, ie2, ll2, le2);
  137.  
  138.    for(i=0; i<ROWS; i++){
  139.       if ( (i%10) == 0) printf(" %d", i);
  140.       for(j=0; j<COLS; j++){
  141.          if( the_image[i][j] != 0   ||
  142.              out_image[i][j] != 0){
  143.              if(the_image[i][j] != 0)
  144.                 out_image[i][j] = the_image[i][j];
  145.              else
  146.                 out_image[i][j] = out_image[i][j];
  147.          }
  148.          else
  149.              out_image[i][j] = 0;
  150.       }  /* ends loop over j */
  151.    }  /* ends loop over i */
  152.  
  153.    write_array_into_tiff_image(out_name, out_image,
  154.                                il3, ie3, ll3, le3);
  155.  
  156. } /* ends or_image */
  157.  
  158.  
  159.  
  160.  
  161.  
  162.    /**************************************************
  163.    *
  164.    *   xor_image(...
  165.    *
  166.    *   This function performs the Boolean XOR 
  167.    *   operation.  The output image = in1 XOR in2.
  168.    *   This works for 0 non-zero images.  If 
  169.    *   in1 is non-zero and in2 is 0, output = in1. If
  170.    *   in2 is non-zero and in1 is 0, output = in2.
  171.    *   If both in1 and in2 are non-zero, output = 0.
  172.    *   If both in1 and in2 are zero, output = 0.
  173.    *
  174.    ***************************************************/
  175.  
  176. xor_image(in1_name, in2_name, out_name,
  177.           the_image, out_image,
  178.           il1, ie1, ll1, le1,
  179.           il2, ie2, ll2, le2,
  180.           il3, ie3, ll3, le3)
  181.    char   in1_name[], in2_name[], out_name[];
  182.    int    il1, ie1, ll1, le1,
  183.           il2, ie2, ll2, le2,
  184.           il3, ie3, ll3, le3;
  185.    short  the_image[ROWS][COLS],
  186.           out_image[ROWS][COLS];
  187. {
  188.    int    i, j, length, width;
  189.    short  answer;
  190.    struct tiff_header_struct image_header;
  191.  
  192.    create_file_if_needed(in1_name, out_name, out_image);
  193.  
  194.    read_tiff_image(in1_name, the_image,
  195.                    il1, ie1, ll1, le1);
  196.    read_tiff_image(in2_name, out_image,
  197.                    il2, ie2, ll2, le2);
  198.  
  199.    for(i=0; i<ROWS; i++){
  200.       if ( (i%10) == 0) printf(" %d", i);
  201.       for(j=0; j<COLS; j++){
  202.          if( (the_image[i][j] != 0 &&
  203.               out_image[i][j] == 0))
  204.              answer = the_image[i][j];
  205.          if( (the_image[i][j] == 0 &&
  206.               out_image[i][j] != 0))
  207.              answer = out_image[i][j];
  208.          if( (the_image[i][j] == 0 &&
  209.               out_image[i][j] == 0))
  210.              answer = 0;
  211.          if( (the_image[i][j] != 0 &&
  212.               out_image[i][j] != 0))
  213.              answer = 0;
  214.          out_image[i][j] = answer;
  215.       }  /* ends loop over j */
  216.    }  /* ends loop over i */
  217.  
  218.    write_array_into_tiff_image(out_name, out_image,
  219.                                il3, ie3, ll3, le3);
  220.  
  221. } /* ends xor_image */
  222.  
  223.  
  224.  
  225.  
  226.  
  227.    /**************************************************
  228.    *
  229.    *   nand_image(...
  230.    *
  231.    *   This function performs the Boolean NAND 
  232.    *   operation.  The output image = in1 NAND in2.
  233.    *   This works for 0 non-zero images.  If both
  234.    *   in1 and in2 are non-zero, the output = 0.
  235.    *   Otherwise, the output = value.
  236.    *
  237.    ***************************************************/
  238.  
  239. nand_image(in1_name, in2_name, out_name,
  240.            the_image, out_image,
  241.            il1, ie1, ll1, le1,
  242.            il2, ie2, ll2, le2,
  243.            il3, ie3, ll3, le3, value)
  244.    char    in1_name[], in2_name[], out_name[];
  245.    int     il1, ie1, ll1, le1,
  246.            il2, ie2, ll2, le2,
  247.            il3, ie3, ll3, le3;
  248.    short   the_image[ROWS][COLS],
  249.            out_image[ROWS][COLS], value;
  250. {
  251.    int    i, j, length, width;
  252.    struct tiff_header_struct image_header;
  253.  
  254.    create_file_if_needed(in1_name, out_name, out_image);
  255.  
  256.    read_tiff_image(in1_name, the_image,
  257.                    il1, ie1, ll1, le1);
  258.    read_tiff_image(in2_name, out_image,
  259.                    il2, ie2, ll2, le2);
  260.  
  261.    for(i=0; i<ROWS; i++){
  262.       if ( (i%10) == 0) printf(" %d", i);
  263.       for(j=0; j<COLS; j++){
  264.          if( the_image[i][j] != 0   &&
  265.              out_image[i][j] != 0)
  266.              out_image[i][j] = 0;
  267.          else
  268.              out_image[i][j] = value;
  269.       }  /* ends loop over j */
  270.    }  /* ends loop over i */
  271.  
  272.    write_array_into_tiff_image(out_name, out_image,
  273.                                il3, ie3, ll3, le3);
  274.  
  275. } /* ends nand_image */
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.    /**************************************************
  283.    *
  284.    *   nor_image(...
  285.    *
  286.    *   This function performs the Boolean NOR 
  287.    *   operation.  The output image = in1 NOR in2.
  288.    *   This works for 0 non-zero images.  If niether
  289.    *   in1 nor in2 are non-zero, the output = value.
  290.    *   That is, if both in1 and in2 are zero, the
  291.    *   output = value.
  292.    *
  293.    ***************************************************/
  294.  
  295. nor_image(in1_name, in2_name, out_name,
  296.           the_image, out_image,
  297.           il1, ie1, ll1, le1,
  298.           il2, ie2, ll2, le2,
  299.           il3, ie3, ll3, le3, value)
  300.    char   in1_name[], in2_name[], out_name[];
  301.    int    il1, ie1, ll1, le1,
  302.           il2, ie2, ll2, le2,
  303.           il3, ie3, ll3, le3;
  304.    short  the_image[ROWS][COLS],
  305.           out_image[ROWS][COLS], value;
  306. {
  307.    int    i, j, length, width;
  308.    struct tiff_header_struct image_header;
  309.  
  310.    create_file_if_needed(in1_name, out_name, out_image);
  311.  
  312.    read_tiff_image(in1_name, the_image,
  313.                    il1, ie1, ll1, le1);
  314.    read_tiff_image(in2_name, out_image,
  315.                    il2, ie2, ll2, le2);
  316.  
  317.    for(i=0; i<ROWS; i++){
  318.       if ( (i%10) == 0) printf(" %d", i);
  319.       for(j=0; j<COLS; j++){
  320.          if( the_image[i][j] == 0   &&
  321.              out_image[i][j] == 0)
  322.              out_image[i][j] = value;
  323.          else
  324.              out_image[i][j] = 0;
  325.       }  /* ends loop over j */
  326.    }  /* ends loop over i */
  327.  
  328.    write_array_into_tiff_image(out_name, out_image,
  329.                                il3, ie3, ll3, le3);
  330.  
  331. } /* ends nor_image */
  332.  
  333.  
  334.  
  335.  
  336.  
  337.    /**************************************************
  338.    *
  339.    *   not_image(...
  340.    *
  341.    *   This function will complement the values of the
  342.    *   input image and put them into the output image.
  343.    *   It will complement using a 0-value scheme where
  344.    *   value is one of the input parameters.
  345.    *
  346.    ***************************************************/
  347.  
  348. not_image(in_name, out_name, the_image, out_image,
  349.           il, ie, ll, le, value)
  350.    char   in_name[], out_name[];
  351.    int    il, ie, ll, le;
  352.    short  the_image[ROWS][COLS],
  353.           out_image[ROWS][COLS],
  354.           value;
  355. {
  356.    int    i, j, length, width;
  357.    struct tiff_header_struct image_header;
  358.  
  359.    create_file_if_needed(in_name, out_name, out_image);
  360.  
  361.    read_tiff_image(in_name, the_image, il, ie, ll, le);
  362.  
  363.    for(i=0; i<ROWS; i++)
  364.       for(j=0; j<COLS; j++)
  365.          out_image[i][j] = value;
  366.  
  367.    for(i=0; i<ROWS; i++){
  368.       if ( (i%10) == 0) printf(" %d", i);
  369.       for(j=0; j<COLS; j++){
  370.          if(the_image[i][j] == value)
  371.              out_image[i][j] = 0;
  372.       }  /* ends loop over j */
  373.    }  /* ends loop over i */
  374.  
  375.    write_array_into_tiff_image(out_name, out_image,
  376.                                il, ie, ll, le);
  377.  
  378. } /* ends not_image */
  379.  
  380.  
  381.  
  382.     /***********************************************
  383.     *
  384.     *       file d:\cips\overlay.c
  385.     *
  386.     *       Functions: This file contains
  387.     *          non_zero_overlay
  388.     *          zero_overlay
  389.     *          greater_overlay
  390.     *          less_overlay
  391.     *          average_overlay
  392.     *
  393.     *       Purpose:
  394.     *          These functions implement the functions
  395.     *          that overlay one image on top of another
  396.     *          image.
  397.     *
  398.     *       External Calls:
  399.     *          wtiff.c - create_file_if_needed
  400.     *                    write_array_into_tiff_image
  401.     *          tiff.c - read_tiff_header
  402.     *          rtiff.c - read_tiff_image
  403.     *          numcvrt.c - get_integer
  404.     *
  405.     *       Modifications:
  406.     *          6 March 1993 - created
  407.     *
  408.     ***********************************************/
  409.  
  410.  
  411.  
  412.  
  413.  
  414.    /**************************************************
  415.    *
  416.    *   non_zero_overlay(...
  417.    *
  418.    *   This function overlays in1 on top of in2
  419.    *   and writes the result to the output image.
  420.    *   It writes any non-zero pixel from in1 on top
  421.    *   of in2.
  422.    *
  423.    ***************************************************/
  424.  
  425. non_zero_overlay(in1_name, in2_name, out_name,
  426.           the_image, out_image,
  427.           il1, ie1, ll1, le1,
  428.           il2, ie2, ll2, le2,
  429.           il3, ie3, ll3, le3)
  430.    char   in1_name[], in2_name[], out_name[];
  431.    int    il1, ie1, ll1, le1,
  432.           il2, ie2, ll2, le2,
  433.           il3, ie3, ll3, le3;
  434.    short  the_image[ROWS][COLS],
  435.           out_image[ROWS][COLS];
  436. {
  437.    int    i, j, length, width;
  438.    struct tiff_header_struct image_header;
  439.  
  440.    create_file_if_needed(in1_name, out_name, out_image);
  441.  
  442.    read_tiff_image(in1_name, the_image,
  443.                    il1, ie1, ll1, le1);
  444.    read_tiff_image(in2_name, out_image,
  445.                    il2, ie2, ll2, le2);
  446.  
  447.    for(i=0; i<ROWS; i++){
  448.       if ( (i%10) == 0) printf(" %d", i);
  449.       for(j=0; j<COLS; j++){
  450.          if(the_image[i][j] != 0)
  451.             out_image[i][j] = the_image[i][j];
  452.       }  /* ends loop over j */
  453.    }  /* ends loop over i */
  454.  
  455.    write_array_into_tiff_image(out_name, out_image,
  456.                                il3, ie3, ll3, le3);
  457.  
  458. } /* ends non_zero_overlay */
  459.  
  460.  
  461.  
  462.  
  463.  
  464.    /**************************************************
  465.    *
  466.    *   zero_overlay(...
  467.    *
  468.    *   This function overlays in1 on top of in2
  469.    *   and writes the result to the output image.
  470.    *   It writes any zero pixel from in1 on top
  471.    *   of in2.
  472.    *
  473.    ***************************************************/
  474.  
  475. zero_overlay(in1_name, in2_name, out_name,
  476.          the_image, out_image,
  477.          il1, ie1, ll1, le1,
  478.          il2, ie2, ll2, le2,
  479.          il3, ie3, ll3, le3)
  480.    char  in1_name[], in2_name[], out_name[];
  481.    int   il1, ie1, ll1, le1,
  482.          il2, ie2, ll2, le2,
  483.          il3, ie3, ll3, le3;
  484.    short the_image[ROWS][COLS],
  485.          out_image[ROWS][COLS];
  486. {
  487.    int    i, j, length, width;
  488.    struct tiff_header_struct image_header;
  489.  
  490.    create_file_if_needed(in1_name, out_name, out_image);
  491.  
  492.    read_tiff_image(in1_name, the_image,
  493.                    il1, ie1, ll1, le1);
  494.    read_tiff_image(in2_name, out_image,
  495.                    il2, ie2, ll2, le2);
  496.  
  497.    for(i=0; i<ROWS; i++){
  498.       if ( (i%10) == 0) printf(" %d", i);
  499.       for(j=0; j<COLS; j++){
  500.          if(the_image[i][j] == 0)
  501.             out_image[i][j] = the_image[i][j];
  502.       }  /* ends loop over j */
  503.    }  /* ends loop over i */
  504.  
  505.    write_array_into_tiff_image(out_name, out_image,
  506.                                il3, ie3, ll3, le3);
  507.  
  508. } /* ends zero_overlay */
  509.  
  510.  
  511.  
  512.  
  513.  
  514.    /**************************************************
  515.    *
  516.    *   greater_overlay(...
  517.    *
  518.    *   This function overlays in1 on top of in2
  519.    *   and writes the result to the output image.
  520.    *   It writes in1 on top of in2 if the value of
  521.    *   in1 is greater than in2.
  522.    *
  523.    ***************************************************/
  524.  
  525. greater_overlay(in1_name, in2_name, out_name,
  526.          the_image, out_image,
  527.          il1, ie1, ll1, le1,
  528.          il2, ie2, ll2, le2,
  529.          il3, ie3, ll3, le3)
  530.    char  in1_name[], in2_name[], out_name[];
  531.    int   il1, ie1, ll1, le1,
  532.          il2, ie2, ll2, le2,
  533.          il3, ie3, ll3, le3;
  534.    short the_image[ROWS][COLS],
  535.          out_image[ROWS][COLS];
  536. {
  537.    int    i, j, length, width;
  538.    struct tiff_header_struct image_header;
  539.  
  540.    create_file_if_needed(in1_name, out_name, out_image);
  541.  
  542.    read_tiff_image(in1_name, the_image,
  543.                    il1, ie1, ll1, le1);
  544.    read_tiff_image(in2_name, out_image,
  545.                    il2, ie2, ll2, le2);
  546.  
  547.    for(i=0; i<ROWS; i++){
  548.       if ( (i%10) == 0) printf(" %d", i);
  549.       for(j=0; j<COLS; j++){
  550.          if(the_image[i][j] > out_image[i][j])
  551.             out_image[i][j] = the_image[i][j];
  552.       }  /* ends loop over j */
  553.    }  /* ends loop over i */
  554.  
  555.    write_array_into_tiff_image(out_name, out_image,
  556.                                il3, ie3, ll3, le3);
  557.  
  558. } /* ends greater_overlay */
  559.  
  560.  
  561.  
  562.  
  563.  
  564.    /**************************************************
  565.    *
  566.    *   less_overlay(...
  567.    *
  568.    *   This function overlays in1 on top of in2
  569.    *   and writes the result to the output image.
  570.    *   It writes in1 on top of in2 if the value of
  571.    *   in1 is less than in2.
  572.    *
  573.    ***************************************************/
  574.  
  575. less_overlay(in1_name, in2_name, out_name,
  576.          the_image, out_image,
  577.          il1, ie1, ll1, le1,
  578.          il2, ie2, ll2, le2,
  579.          il3, ie3, ll3, le3)
  580.    char  in1_name[], in2_name[], out_name[];
  581.    int   il1, ie1, ll1, le1,
  582.          il2, ie2, ll2, le2,
  583.          il3, ie3, ll3, le3;
  584.    short the_image[ROWS][COLS],
  585.          out_image[ROWS][COLS];
  586. {
  587.    int    i, j, length, width;
  588.    struct tiff_header_struct image_header;
  589.  
  590.    create_file_if_needed(in1_name, out_name, out_image);
  591.  
  592.    read_tiff_image(in1_name, the_image,
  593.                    il1, ie1, ll1, le1);
  594.    read_tiff_image(in2_name, out_image,
  595.                    il2, ie2, ll2, le2);
  596.  
  597.    for(i=0; i<ROWS; i++){
  598.       if ( (i%10) == 0) printf(" %d", i);
  599.       for(j=0; j<COLS; j++){
  600.          if(the_image[i][j] < out_image[i][j])
  601.             out_image[i][j] = the_image[i][j];
  602.       }  /* ends loop over j */
  603.    }  /* ends loop over i */
  604.  
  605.    write_array_into_tiff_image(out_name, out_image,
  606.                                il3, ie3, ll3, le3);
  607.  
  608. } /* ends less_overlay */
  609.  
  610.  
  611.  
  612.  
  613.  
  614.    /**************************************************
  615.    *
  616.    *   average_overlay(...
  617.    *
  618.    *   This function mixes in1 and in2
  619.    *   and writes the result to the output image.
  620.    *   It writes the average of in1 and in2 to the
  621.    *   output image.
  622.    *
  623.    ***************************************************/
  624.  
  625. average_overlay(in1_name, in2_name, out_name,
  626.          the_image, out_image,
  627.          il1, ie1, ll1, le1,
  628.          il2, ie2, ll2, le2,
  629.          il3, ie3, ll3, le3)
  630.    char  in1_name[], in2_name[], out_name[];
  631.    int   il1, ie1, ll1, le1,
  632.          il2, ie2, ll2, le2,
  633.          il3, ie3, ll3, le3;
  634.    short the_image[ROWS][COLS],
  635.          out_image[ROWS][COLS];
  636. {
  637.    int    i, j, length, width;
  638.    struct tiff_header_struct image_header;
  639.  
  640.    create_file_if_needed(in1_name, out_name, out_image);
  641.  
  642.    read_tiff_image(in1_name, the_image,
  643.                    il1, ie1, ll1, le1);
  644.    read_tiff_image(in2_name, out_image,
  645.                    il2, ie2, ll2, le2);
  646.  
  647.    for(i=0; i<ROWS; i++){
  648.       if ( (i%10) == 0) printf(" %d", i);
  649.       for(j=0; j<COLS; j++){
  650.          out_image[i][j] =
  651.             (the_image[i][j] + out_image[i][j])/2;
  652.       }  /* ends loop over j */
  653.    }  /* ends loop over i */
  654.  
  655.    write_array_into_tiff_image(out_name, out_image,
  656.                                il3, ie3, ll3, le3);
  657.  
  658. } /* ends average_overlay */
  659.  
  660.     /***********************************************
  661.     *
  662.     *    file d:\cips\txtrsubs.c
  663.     *
  664.     *    Functions: This file contains
  665.     *       sigma
  666.     *       skewness
  667.     *       amean
  668.     *       adifference
  669.     *       difference_array
  670.     *       hurst
  671.     *       compare
  672.     *       get_texture_options
  673.     *
  674.     *    Purpose:
  675.     *       These functions calculate measures
  676.     *       that help distinguish textures.
  677.     *
  678.     *    External Calls:
  679.     *       wtiff.c - round_off_image_size
  680.     *                 create_file_if_needed
  681.     *                 write_array_into_tiff_image
  682.     *       tiff.c - read_tiff_header
  683.     *       rtiff.c - read_tiff_image
  684.     *       edge.c - fix_edges
  685.     *       fitt.c - fit
  686.     *       filter.c - sort_elements
  687.     *
  688.     *    Modifications:
  689.     *       12 August 1993- created
  690.     *
  691.     *************************************************/
  692.  
  693.  
  694.  
  695.  
  696.      /*******************************************
  697.      *
  698.      *   sigma(..
  699.      *
  700.      *   This calculates the variance and the 
  701.      *   sigma for a sizeXsize area.
  702.      *
  703.      *   It sums the squares of the difference
  704.      *   between each pixel and the mean of
  705.      *   the area and divides that by the
  706.      *   number of pixels in the area.
  707.      *
  708.      *   The output image is set to the square
  709.      *   root of the variance since the variance
  710.      *   will almost certainly be out of range
  711.      *   for the image.  The square root of the
  712.      *   variance will be sigma.
  713.      *
  714.      *******************************************/
  715.  
  716. sigma(in_name, out_name, the_image, out_image,
  717.       il, ie, ll, le, size, threshold, high)
  718.    char   in_name[], out_name[];
  719.    int    il, ie, ll, le,
  720.           high, threshold, size;
  721.    short  the_image[ROWS][COLS],
  722.           out_image[ROWS][COLS];
  723. {
  724.    int      a, b, count, i, j, k,
  725.             max, mean, new_hi, new_low,
  726.             sd2, sd2p1;
  727.    short    sigma;
  728.    struct   tiff_header_struct image_header;
  729.    unsigned long diff, variance;
  730.  
  731.    sd2   = size/2;
  732.    sd2p1 = sd2 + 1;
  733.  
  734.    create_file_if_needed(in_name, out_name, out_image);
  735.  
  736.    read_tiff_image(in_name, the_image, il, ie, ll, le);
  737.  
  738.    max     = 255;
  739.    new_hi  = 250;
  740.    new_low = 16;
  741.    if(image_header.bits_per_pixel == 4){
  742.        new_hi  = 10;
  743.        new_low = 3;
  744.        max     = 16;
  745.    }
  746.  
  747.       /***************************
  748.       *
  749.       *   Loop over image array
  750.       *
  751.       ****************************/
  752.  
  753.    printf("\n");
  754.    for(i=sd2; i<ROWS-sd2; i++){
  755.       if( (i%10) == 0) printf("%d ", i);
  756.       for(j=sd2; j<COLS-sd2; j++){
  757.  
  758.             /*****************************
  759.             *
  760.             *   Run through the small area
  761.             *   and calculate the mean.
  762.             *
  763.             ******************************/
  764.  
  765.          mean = 0;
  766.          for(a=-sd2; a<sd2p1; a++){
  767.             for(b=-sd2; b<sd2p1; b++){
  768.                mean = mean + the_image[i+a][j+b];
  769.             }
  770.          }
  771.          mean = mean/(size*size);
  772.  
  773.             /*****************************
  774.             *
  775.             *   Run through the small area
  776.             *   again and the calculate the
  777.             *   variance.
  778.             *
  779.             ******************************/
  780.  
  781.          variance = 0;
  782.          diff     = 0;
  783.          for(a=-sd2; a<sd2p1; a++){
  784.             for(b=-sd2; b<sd2p1; b++){
  785.                diff     = the_image[i+a][j+b] - mean;
  786.                variance = variance + (diff*diff);
  787.             }
  788.          }
  789.  
  790.          variance = variance/(size*size);
  791.          sigma    = sqrt(variance);
  792.          if(sigma > max) sigma = max;
  793.          out_image[i][j] = sigma;
  794.  
  795.       }  /* ends loop over j */
  796.    }  /* ends loop over i */
  797.  
  798.  
  799.      /* if desired, threshold the output image */
  800.    if(threshold == 1){
  801.        for(i=0; i<ROWS; i++){
  802.           for(j=0; j<COLS; j++){
  803.              if(out_image[i][j] > high){
  804.                   out_image[i][j] = new_hi;
  805.              }
  806.              else{
  807.                   out_image[i][j] = new_low;
  808.              }
  809.           }
  810.        }
  811.    }  /* ends if threshold == 1 */
  812.  
  813.    fix_edges(out_image, sd2);
  814.  
  815.    write_array_into_tiff_image(out_name, out_image,
  816.                                il, ie, ll, le);
  817.  
  818.  
  819. }  /* ends sigma */
  820.  
  821.  
  822.  
  823.  
  824.  
  825.      /*******************************************
  826.      *
  827.      *   skewness(..
  828.      *
  829.      *   This calculates the skewness for a
  830.      *   sizeXsize area.
  831.      *
  832.      *   Look at Levine's book page 449 for
  833.      *   the formula.
  834.      *   "Vision in Man and Machine" by
  835.      *   Martin D. Levine, McGraw Hill, 1985.
  836.      *
  837.      *******************************************/
  838.  
  839. skewness(in_name, out_name, the_image, out_image,
  840.          il, ie, ll, le, size, threshold, high)
  841.    char   in_name[], out_name[];
  842.    int    il, ie, ll, le,
  843.           high, threshold, size;
  844.    short  the_image[ROWS][COLS],
  845.           out_image[ROWS][COLS];
  846. {
  847.    int      a, b, count, i, j, k,
  848.             max, mean, new_hi, new_low,
  849.             sd2, sd2p1;
  850.    long     cube;
  851.    short    sigma, skew;
  852.    struct   tiff_header_struct image_header;
  853.    unsigned long diff, sigma3, variance;
  854.  
  855.    sd2   = size/2;
  856.    sd2p1 = sd2 + 1;
  857.  
  858.    create_file_if_needed(in_name, out_name, out_image);
  859.  
  860.    read_tiff_image(in_name, the_image, il, ie, ll, le);
  861.  
  862.    max     = 255;
  863.    new_hi  = 250;
  864.    new_low = 16;
  865.    if(image_header.bits_per_pixel == 4){
  866.        new_hi  = 10;
  867.        new_low = 3;
  868.        max     = 16;
  869.    }
  870.  
  871.       /***************************
  872.       *
  873.       *   Loop over image array
  874.       *
  875.       ****************************/
  876.  
  877.    printf("\n");
  878.    for(i=sd2; i<ROWS-sd2; i++){
  879.       if( (i%10) == 0) printf("%d ", i);
  880.       for(j=sd2; j<COLS-sd2; j++){
  881.  
  882.             /*****************************
  883.             *
  884.             *   Run through the small area
  885.             *   and calculate the mean.
  886.             *
  887.             ******************************/
  888.  
  889.          mean = 0;
  890.          for(a=-sd2; a<sd2p1; a++){
  891.             for(b=-sd2; b<sd2p1; b++){
  892.                mean = mean + the_image[i+a][j+b];
  893.             }
  894.          }
  895.          mean = mean/(size*size);
  896.  
  897.             /*****************************
  898.             *
  899.             *   Run through the small area
  900.             *   again and the calculate the
  901.             *   variance and the cube.
  902.             *
  903.             ******************************/
  904.  
  905.          variance = 0;
  906.          diff     = 0;
  907.          cube     = 0;
  908.          for(a=-sd2; a<sd2p1; a++){
  909.             for(b=-sd2; b<sd2p1; b++){
  910.                diff     = the_image[i+a][j+b] - mean;
  911.                cube     = cube + (diff*diff*diff);
  912.                variance = variance + (diff*diff);
  913.             }
  914.          }
  915.  
  916.          variance        = variance/(size*size);
  917.          sigma           = sqrt(variance);
  918.          sigma3          = sigma*sigma*sigma;
  919.          if(sigma3 == 0)
  920.             sigma3       = 1;
  921.          skew            = cube/(sigma3*size*size);
  922.          out_image[i][j] = skew;
  923.          if(out_image[i][j] > max)
  924.             out_image[i][j] = max;
  925.  
  926.       }  /* ends loop over j */
  927.    }  /* ends loop over i */
  928.  
  929.  
  930.  
  931.      /* if desired, threshold the output image */
  932.    if(threshold == 1){
  933.        for(i=0; i<ROWS; i++){
  934.           for(j=0; j<COLS; j++){
  935.              if(out_image[i][j] > high){
  936.                   out_image[i][j] = new_hi;
  937.              }
  938.              else{
  939.                   out_image[i][j] = new_low;
  940.              }
  941.           }
  942.        }
  943.    }  /* ends if threshold == 1 */
  944.  
  945.    fix_edges(out_image, sd2);
  946.  
  947.    write_array_into_tiff_image(out_name, out_image,
  948.                                il, ie, ll, le);
  949.  
  950.  
  951. }  /* ends skewness */
  952.  
  953.  
  954.  
  955.  
  956.  
  957.      /*******************************************
  958.      *
  959.      *   amean(..
  960.      *
  961.      *   This calculates the mean measure
  962.      *   for a sizeXsize area.
  963.      *
  964.      *   Look at Levine's book page 451 for
  965.      *   the formula.
  966.      *   "Vision in Man and Machine" by
  967.      *   Martin D. Levine, McGraw Hill, 1985.
  968.      *
  969.      *******************************************/
  970.  
  971. amean(in_name, out_name, the_image, out_image,
  972.           il, ie, ll, le, size)
  973.    char   in_name[], out_name[];
  974.    int    il, ie, ll, le,
  975.           size;
  976.    short  the_image[ROWS][COLS],
  977.           out_image[ROWS][COLS];
  978. {
  979.    int      a, b, count, i, j, k, max,
  980.             sd2, sd2p1;
  981.    short    pixel;
  982.    struct   tiff_header_struct image_header;
  983.    unsigned long big;
  984.  
  985.    sd2   = size/2;
  986.    sd2p1 = sd2 + 1;
  987.  
  988.    create_file_if_needed(in_name, out_name, out_image);
  989.  
  990.    read_tiff_image(in_name, the_image, il, ie, ll, le);
  991.  
  992.    max = 255;
  993.    if(image_header.bits_per_pixel == 4){
  994.        max = 16;
  995.    }
  996.  
  997.       /**************************************
  998.       *
  999.       *   Calculate the gray level difference
  1000.       *   array.
  1001.       *
  1002.       ***************************************/
  1003.  
  1004.    difference_array(the_image, out_image, size);
  1005.    for(i=0; i<ROWS; i++)
  1006.       for(j=0; j<COLS; j++)
  1007.          the_image[i][j] = out_image[i][j];
  1008.  
  1009.       /**************************************
  1010.       *
  1011.       *   Loop over the image array and
  1012.       *   calculate the mean measure.
  1013.       *
  1014.       ***************************************/
  1015.  
  1016.    printf("\n");
  1017.    for(i=sd2; i<ROWS-sd2; i++){
  1018.       if( (i%10) == 0) printf("%d ", i);
  1019.       for(j=sd2; j<COLS-sd2; j++){
  1020.  
  1021.          pixel = 0;
  1022.          for(a=-sd2; a<sd2p1; a++){
  1023.             for(b=-sd2; b<sd2p1; b++){
  1024.                pixel = pixel + the_image[i+a][j+b];
  1025.             }
  1026.          }
  1027.       out_image[i][j] = pixel/(size*size);
  1028.       if(out_image[i][j] > max)
  1029.          out_image[i][j] = max;
  1030.  
  1031.       }  /* ends loop over j */
  1032.    }  /* ends loop over i */
  1033.  
  1034.    fix_edges(out_image, sd2);
  1035.  
  1036.    write_array_into_tiff_image(out_name, out_image,
  1037.                                il, ie, ll, le);
  1038.  
  1039. }  /* ends amean */
  1040.  
  1041.  
  1042.  
  1043.  
  1044.  
  1045.      /*******************************************
  1046.      *
  1047.      *   adifference(..
  1048.      *
  1049.      *   This function performs the difference
  1050.      *   operation for a specified array
  1051.      *   in an image file.
  1052.      *
  1053.      *******************************************/
  1054.  
  1055. adifference(in_name, out_name, the_image, out_image,
  1056.             il, ie, ll, le, size)
  1057.    char   in_name[], out_name[];
  1058.    int    il, ie, ll, le,
  1059.           size;
  1060.    short  the_image[ROWS][COLS],
  1061.           out_image[ROWS][COLS];
  1062. {
  1063.    int      sd2, sd2p1;
  1064.    struct   tiff_header_struct image_header;
  1065.  
  1066.    sd2   = size/2;
  1067.    sd2p1 = sd2 + 1;
  1068.  
  1069.    create_file_if_needed(in_name, out_name, out_image);
  1070.  
  1071.    read_tiff_image(in_name, the_image, il, ie, ll, le);
  1072.  
  1073.    difference_array(the_image, out_image, size);
  1074.  
  1075.    fix_edges(out_image, sd2);
  1076.  
  1077.    write_array_into_tiff_image(out_name, out_image,
  1078.                                il, ie, ll, le);
  1079.  
  1080. }  /* ends adifference */
  1081.  
  1082.  
  1083.  
  1084.  
  1085.  
  1086.      /*******************************************
  1087.      *
  1088.      *   difference_array(..
  1089.      *
  1090.      *   This function takes the input image
  1091.      *   array the_image and places in out_image
  1092.      *   the gray level differences of the pixels
  1093.      *   in the_image.  It uses the size
  1094.      *   parameter for the distance between pixels
  1095.      *   used to get the difference.
  1096.      *
  1097.      *******************************************/
  1098.  
  1099. difference_array(the_image, out_image, size)
  1100.    int    size;
  1101.    short  the_image[ROWS][COLS],
  1102.           out_image[ROWS][COLS];
  1103. {
  1104.    int i, j, sd2;
  1105.    sd2   = size/2;
  1106.  
  1107.    for(i=sd2; i<ROWS-sd2; i++){
  1108.       for(j=sd2; j<COLS-sd2; j++){
  1109.          out_image[i][j] =
  1110.             abs(the_image[i][j] - 
  1111.                 the_image[i+sd2][j+sd2]);
  1112.       }  /* ends loop over j */
  1113.    }  /* ends loop over i */
  1114.  
  1115.    fix_edges(out_image, sd2);
  1116.  
  1117. }  /* ends difference_array */
  1118.  
  1119.  
  1120.  
  1121.      /*******************************************
  1122.      *
  1123.      *   hurst(..
  1124.      *
  1125.      *   This routine performs the Hurst 
  1126.      *   operation as described in "The Image 
  1127.      *   Processing Handbook" by John C. Russ
  1128.      *   CRC Press 1992.
  1129.      *
  1130.      *   The following show the definitions of
  1131.      *   the pixel classes used in this routine.
  1132.      *
  1133.      *   3x3 case
  1134.      *       c b c
  1135.      *     d b a b d
  1136.      *       c b c
  1137.      *
  1138.      *   5x5 case
  1139.      *     f e d e f
  1140.      *     e c b c e
  1141.      *     d b a b d
  1142.      *     e c b c e
  1143.      *     f e d e f
  1144.      *
  1145.      *   7x7 case
  1146.      *       h g h
  1147.      *     f e d e f
  1148.      *   h e c b c e h
  1149.      *   g d b a b d g
  1150.      *   h e c b c e h
  1151.      *     f e d e f
  1152.      *       h g h
  1153.      *
  1154.      *******************************************/
  1155.  
  1156. hurst(in_name, out_name, the_image, out_image,
  1157.       il, ie, ll, le, size)
  1158.    char   in_name[], out_name[];
  1159.    int    il, ie, ll, le, size;
  1160.    short  the_image[ROWS][COLS],
  1161.           out_image[ROWS][COLS];
  1162.  
  1163. {
  1164.    float  x[8], y[8], sig[8];
  1165.    float  aa, bb, siga, sigb, chi2, q;
  1166.    int    ndata, mwt;
  1167.  
  1168.    int    a, b, count, i, j, k,
  1169.           new_hi, new_low, length,
  1170.           number, sd2, sd2p1, ss, width;
  1171.    short  *elements, max, prange;
  1172.    struct tiff_header_struct image_header;
  1173.  
  1174.       /**********************************************
  1175.       *
  1176.       *   Initialize the ln's of the distances.
  1177.       *   Do this one time to save computations.
  1178.       *
  1179.       **********************************************/
  1180.  
  1181.    x[1] = 0.0;        /* ln(1)        */
  1182.    x[2] = 0.34657359; /* ln(sqrt(2))  */
  1183.    x[3] = 0.69314718; /* ln(2)        */
  1184.    x[4] = 0.80471896; /* ln(sqrt(5))  */
  1185.    x[5] = 1.03972077; /* ln(sqrt(8))  */
  1186.    x[6] = 1.09861229; /* ln(3)        */
  1187.    x[7] = 1.15129255; /* ln(sqrt(10)) */
  1188.  
  1189.    sig[1] = 1.0;
  1190.    sig[2] = 1.0;
  1191.    sig[3] = 1.0;
  1192.    sig[4] = 1.0;
  1193.    sig[5] = 1.0;
  1194.    sig[6] = 1.0;
  1195.    sig[7] = 1.0;
  1196.  
  1197.    sd2 = size/2;
  1198.  
  1199.       /**********************************
  1200.       *
  1201.       *   Create out file and read
  1202.       *   input file.
  1203.       *
  1204.       ***********************************/
  1205.  
  1206.    create_file_if_needed(in_name, out_name, out_image);
  1207.  
  1208.    read_tiff_image(in_name, the_image, il, ie, ll, le);
  1209.  
  1210.    max = 255;
  1211.    if(image_header.bits_per_pixel == 4){
  1212.       max = 16;
  1213.    }
  1214.  
  1215.       /***************************
  1216.       *
  1217.       *   Loop over image array
  1218.       *
  1219.       ****************************/
  1220.  
  1221.    printf("\n");
  1222.    for(i=sd2; i<ROWS-sd2; i++){
  1223.       if( (i%2) == 0) printf("%d ", i);
  1224.       for(j=sd2; j<COLS-sd2; j++){
  1225.  
  1226.          for(k=1; k<=7; k++) y[k] = 0.0;
  1227.  
  1228.             /*************************************
  1229.             *
  1230.             *   Go through each pixel class, set
  1231.             *   the elements array, sort it, get
  1232.             *   the range, and take the ln of the
  1233.             *   range.
  1234.             *
  1235.             *************************************/
  1236.  
  1237.             /* b pixel class */
  1238.          number      = 4;
  1239.          elements    = (short *)
  1240.                        malloc(number * sizeof(short));
  1241.          elements[0] = the_image[i-1][j];
  1242.          elements[1] = the_image[i+1][j];
  1243.          elements[2] = the_image[i][j-1];
  1244.          elements[3] = the_image[i][j+1];
  1245.          sort_elements(elements, &number);
  1246.          prange = elements[number-1] - elements[0];
  1247.          if(prange < 0)  prange = prange*(-1);
  1248.          if(prange == 0) prange = 1;
  1249.          y[1] = log(prange);
  1250.  
  1251.             /* c pixel class */
  1252.          elements[0] = the_image[i-1][j-1];
  1253.          elements[1] = the_image[i+1][j+1];
  1254.          elements[2] = the_image[i+1][j-1];
  1255.          elements[3] = the_image[i-1][j+1];
  1256.          sort_elements(elements, &number);
  1257.          prange = elements[number-1] - elements[0];
  1258.          if(prange < 0)  prange = prange*(-1);
  1259.          if(prange == 0) prange = 1;
  1260.          y[2] = log(prange);
  1261.  
  1262.             /* d pixel class */
  1263.          elements[0] = the_image[i-2][j];
  1264.          elements[1] = the_image[i+2][j];
  1265.          elements[2] = the_image[i][j-2];
  1266.          elements[3] = the_image[i][j+2];
  1267.          sort_elements(elements, &number);
  1268.          prange = elements[number-1] - elements[0];
  1269.          if(prange < 0)  prange = prange*(-1);
  1270.          if(prange == 0) prange = 1;
  1271.          y[3] = log(prange);
  1272.  
  1273.             /* f pixel class */
  1274.          if(size == 5  ||  size == 7){
  1275.          elements[0] = the_image[i-2][j-2];
  1276.          elements[1] = the_image[i+2][j+2];
  1277.          elements[2] = the_image[i+2][j-2];
  1278.          elements[3] = the_image[i-2][j+2];
  1279.          sort_elements(elements, &number);
  1280.          prange = elements[number-1] - elements[0];
  1281.          if(prange < 0)  prange = prange*(-1);
  1282.          if(prange == 0) prange = 1;
  1283.          y[5] = log(prange);
  1284.          }  /* ends if size == 5 */
  1285.  
  1286.             /* g pixel class */
  1287.          if(size == 7){
  1288.          elements[0] = the_image[i-3][j];
  1289.          elements[1] = the_image[i+3][j];
  1290.          elements[2] = the_image[i][j-3];
  1291.          elements[3] = the_image[i][j+3];
  1292.          sort_elements(elements, &number);
  1293.          prange = elements[number-1] - elements[0];
  1294.          if(prange < 0)  prange = prange*(-1);
  1295.          if(prange == 0) prange = 1;
  1296.          y[6] = log(prange);
  1297.          }  /* ends if size == 7 */
  1298.  
  1299.          free(elements);
  1300.  
  1301.             /* e pixel class */
  1302.          if(size == 5  ||  size == 7){
  1303.          number      = 8;
  1304.          elements    = (short *)
  1305.                        malloc(number * sizeof(short));
  1306.          elements[0] = the_image[i-1][j-2];
  1307.          elements[1] = the_image[i-2][j-1];
  1308.          elements[2] = the_image[i-2][j+1];
  1309.          elements[3] = the_image[i-1][j+2];
  1310.          elements[4] = the_image[i+1][j+2];
  1311.          elements[5] = the_image[i+2][j+1];
  1312.          elements[6] = the_image[i+2][j-1];
  1313.          elements[7] = the_image[i+1][j-2];
  1314.          sort_elements(elements, &number);
  1315.          prange = elements[number-1] - elements[0];
  1316.          if(prange < 0)  prange = prange*(-1);
  1317.          if(prange == 0) prange = 1;
  1318.          y[4] = log(prange);
  1319.          }  /* ends if size == 5 */
  1320.  
  1321.             /* h pixel class */
  1322.          if(size == 7){
  1323.          elements[0] = the_image[i-1][j-3];
  1324.          elements[1] = the_image[i-3][j-1];
  1325.          elements[2] = the_image[i-3][j+1];
  1326.          elements[3] = the_image[i-1][j+3];
  1327.          elements[4] = the_image[i+1][j+3];
  1328.          elements[5] = the_image[i+3][j+1];
  1329.          elements[6] = the_image[i+3][j-1];
  1330.          elements[7] = the_image[i+1][j-3];
  1331.          sort_elements(elements, &number);
  1332.          prange = elements[number-1] - elements[0];
  1333.          if(prange < 0)  prange = prange*(-1);
  1334.          if(prange == 0) prange = 1;
  1335.          y[7] = log(prange);
  1336.          }  /* ends if size == 7 */
  1337.  
  1338.          free(elements);
  1339.  
  1340.             /*************************************
  1341.             *
  1342.             *   Call the fit routine to fit the
  1343.             *   data to a straight line. y=mx+b
  1344.             *   The answer you want is the slope
  1345.             *   of the line.  That is returned
  1346.             *   in the parameter bb.
  1347.             *
  1348.             *************************************/
  1349.          ndata = size;
  1350.          mwt   = 1;
  1351.          fit(x, y, ndata, sig, mwt, &aa, &bb,
  1352.              &siga, &sigb, &chi2, &q);
  1353.  
  1354.          out_image[i][j] = (short)(bb*64.0);
  1355.          if(out_image[i][j] > max)
  1356.             out_image[i][j] = max;
  1357.          if(out_image[i][j] < 0)
  1358.             out_image[i][j] = 0;
  1359.  
  1360.       }  /* ends loop over j */
  1361.    }  /* ends loop over i */
  1362.  
  1363.  
  1364.    fix_edges(out_image, sd2);
  1365.  
  1366.    write_array_into_tiff_image(out_name, out_image,
  1367.                                il, ie, ll, le);
  1368.  
  1369. }  /* ends hurst */
  1370.  
  1371.  
  1372.  
  1373.  
  1374.  
  1375.      /*******************************************
  1376.      *
  1377.      *   compare(..
  1378.      *
  1379.      *   This function compares a sizeXsize area
  1380.      *   starting at line,element in an image
  1381.      *   with all the sizeXsize areas in the
  1382.      *   image.
  1383.      *
  1384.      *******************************************/
  1385.  
  1386. compare(in_name, out_name, the_image, out_image,
  1387.           il, ie, ll, le, line, element, size)
  1388.    char   in_name[], out_name[];
  1389.    int    il, ie, ll, le,
  1390.           line, element, size;
  1391.    short  the_image[ROWS][COLS],
  1392.           out_image[ROWS][COLS];
  1393. {
  1394.    int      a, b, count, i, j, k, max,
  1395.             sd2, sd2p1;
  1396.    short    pixel;
  1397.    struct   tiff_header_struct image_header;
  1398.    int      big, diff;
  1399.  
  1400.       /**************************************
  1401.       *
  1402.       *   Declare and allocate memory for the
  1403.       *   two dimensional small array.
  1404.       *
  1405.       ***************************************/
  1406.  
  1407.    short **small;
  1408.    small = malloc(size * sizeof(short  *));
  1409.    for(i=0; i<size; i++){
  1410.       small[i] = malloc(size * sizeof(short ));
  1411.       if(small[i] == '\0'){
  1412.          printf("\n\tmalloc of small[%d] failed", i);
  1413.          exit(0);
  1414.       }
  1415.    }
  1416.  
  1417.       /**************************************
  1418.       *
  1419.       *   Read in the part of the input image
  1420.       *   that contains the line element
  1421.       *   portion.
  1422.       *
  1423.       ***************************************/
  1424.  
  1425.    read_tiff_image(in_name, the_image,
  1426.                    line, element,
  1427.                    line+size, element+size);
  1428.  
  1429.    for(i=0; i<size; i++)
  1430.       for(j=0; j<size; j++)
  1431.         small[i][j] = the_image[i][j];
  1432.  
  1433.       /**************************************
  1434.       *
  1435.       *   Create the output image and read
  1436.       *   in the input data.
  1437.       *
  1438.       ***************************************/
  1439.  
  1440.    sd2   = size/2;
  1441.    sd2p1 = sd2 + 1;
  1442.  
  1443.    create_file_if_needed(in_name, out_name, out_image);
  1444.  
  1445.    read_tiff_image(in_name, the_image, il, ie, ll, le);
  1446.  
  1447.    max = 255;
  1448.    if(image_header.bits_per_pixel == 4){
  1449.        max = 16;
  1450.    }
  1451.  
  1452.       /**************************************
  1453.       *
  1454.       *   Loop over the image array and
  1455.       *   calculate the contrast measure.
  1456.       *
  1457.       ***************************************/
  1458.  
  1459.    printf("\n");
  1460.    for(i=sd2; i<ROWS-sd2; i++){
  1461.       if( (i%10) == 0) printf("%d ", i);
  1462.       for(j=sd2; j<COLS-sd2; j++){
  1463.  
  1464.          big = 0;
  1465.          for(a=-sd2; a<sd2p1; a++){
  1466.             for(b=-sd2; b<sd2p1; b++){
  1467.             diff = small[a+sd2][b+sd2] -
  1468.                    the_image[i+a][j+b];
  1469.             big  = big + abs(diff);
  1470.             }
  1471.          }
  1472.  
  1473.       big = big/(size*size);
  1474.       out_image[i][j] = big;
  1475.       if(out_image[i][j] > max)
  1476.          out_image[i][j] = max;
  1477.  
  1478.       }  /* ends loop over j */
  1479.    }  /* ends loop over i */
  1480.  
  1481.    fix_edges(out_image, sd2);
  1482.  
  1483.    write_array_into_tiff_image(out_name, out_image,
  1484.                                il, ie, ll, le);
  1485.  
  1486.       /**************************************
  1487.       *
  1488.       *   Free the memory for the
  1489.       *   two dimensional small array.
  1490.       *
  1491.       ***************************************/
  1492.  
  1493.    for(i=0; i<size; i++)
  1494.       free(small[i]);
  1495.  
  1496. }  /* ends compare */
  1497.  
  1498.  
  1499.  
  1500.  
  1501.  
  1502.      /*******************************************
  1503.      *
  1504.      *   get_texture_options(..
  1505.      *
  1506.      *   This function queries the user for the
  1507.      *   parameters needed to use the texture
  1508.      *   operators.
  1509.      *
  1510.      *******************************************/
  1511.  
  1512. get_texture_options(type, threshold, t_value, size, 
  1513.                     line, element)
  1514.    char type[];
  1515.    int  *threshold, *t_value, *size, *line, *element;
  1516. {
  1517.    int not_finished = 1, response;
  1518.  
  1519.    while(not_finished){
  1520.  
  1521.       printf("\n");
  1522.       printf("\n1. Type of texture operator is %s",
  1523.              type);  
  1524.       printf("\n   recall type: sigma      skewness");
  1525.       printf("\n                amean      adifference");
  1526.       printf("\n                hurst      compare");
  1527.       printf("\n2. threshold is %d (1=on 2=off)",
  1528.              *threshold);
  1529.       printf("\n3. threshold value is %d", *t_value);
  1530.       printf("\n4. size is %d", *size);
  1531.       printf("\n5. line is %d", *line);
  1532.       printf("\n6. element is %d\n", *element);
  1533.       printf("\n   usage for compare:");
  1534.       printf("\n   texture in-file out-file compare ");
  1535.       printf("line element size");
  1536.       printf("\n\nEnter choice (0 = no change) _\b");
  1537.  
  1538.       get_integer(&response);
  1539.  
  1540.       if(response == 0){
  1541.         not_finished = 0;
  1542.       }
  1543.  
  1544.       if(response == 1){
  1545.          printf("\nEnter type of texture operator");
  1546.          printf("\nrecall type: sigma  skewness");
  1547.          printf("\n             amean  adifference");
  1548.          printf("\n             hurst  compare\n");
  1549.          gets(type);
  1550.       }
  1551.  
  1552.       if(response == 2){
  1553.         printf("\n\nEnter threshold output ");
  1554.         printf("(1=on 2=off)");
  1555.         printf("\n  _\b");
  1556.         get_integer(threshold);
  1557.       }
  1558.  
  1559.       if(response == 3){
  1560.         printf("\n\nEnter threshold value");
  1561.         printf("\n  _\b");
  1562.         get_integer(t_value);
  1563.       }
  1564.  
  1565.       if(response == 4){
  1566.         printf("\n\nEnter size");
  1567.         printf("\n  _\b");
  1568.         get_integer(size);
  1569.       }
  1570.  
  1571.       if(response == 5){
  1572.         printf("\n\nEnter line");
  1573.         printf("\n  _\b");
  1574.         get_integer(line);
  1575.       }
  1576.  
  1577.       if(response == 6){
  1578.         printf("\n\nEnter element");
  1579.         printf("\n  _\b");
  1580.         get_integer(element);
  1581.       }
  1582.  
  1583.    }  /* ends while not_finished */
  1584. }  /* ends get_texture_options */
  1585.